package com.crm.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.crm.dto.LoginDto;
import com.crm.entity.User;
import com.crm.exception.BaseException;
import com.crm.mapper.UserMapper;
import com.crm.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(LoginDto loginDto) {
        User user = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUserName, loginDto.getUsername()));
        if (user == null){
            throw new BaseException("用户不存在");
        }
        if (!user.getPassword().equals(loginDto.getPassword())){
            throw new BaseException("密码错误");
        }
        return user;
    }
}
